package com.itheima.test;

import java.util.ArrayList;

public class ArrayList05 {
    public static void main(String[] args) {
        // 1.定义集合
        ArrayList<User> list = new ArrayList<>();

        User u1 = new User(1, "张三", "123");
        User u2 = new User(2, "李四", "123456");
        User u3 = new User(3, "王五", "123789");

        list.add(u1);
        list.add(u2);
        list.add(u3);

        boolean isExist = checkUser(list,4);
        System.out.println(isExist);
    }


    // 查询方法
    public static boolean checkUser(ArrayList<User> list, int id) {
        for (int i = 0; i < list.size(); i++) {
            User user = list.get(i);
            if (user.getId() == id) {
                return true;
            }
        }

        return false;
    }
}
